package com.owc.common.context;

import lombok.Data;

/**
 * @Author xiaom
 * @Date 2019/11/4 16:09
 * @Version 1.0.0
 * @Description <Development environment profile>
 **/
@Data
public class ActiveProfile {

    private static final String DEV            = "dev";
    private static final String PROD           = "pro";
    private static final String TEST           = "test";
    private static final String RELEASE        = "release";

    private static String active ;

    static {
        loadActiveProfile();
    }

    /**
     * Is development environment.
     * @return bool
     */
    public static boolean isDev() {
        return DEV.equals(active);
    }

    /**
     * Load the current system runtime environment.
     */
    private synchronized static void loadActiveProfile(){
        if(active == null){
            active = SpringContext.getApplicationContext().getEnvironment().getActiveProfiles()[0];
        }
    }

    public static boolean isProd() {
        return PROD.equals(active);
    }

    public static boolean isRelease(){
        return RELEASE.equals(active);
    }

    public static boolean isTest(){
        return TEST.equals(active);
    }

    public static String getActive() {
        return active;
    }
}
